var BTree = function(text, value){
	var children = {};
	var values = [];
	var skipList;
	
	this.add = function(text, value){
		if(!text || text == ""){
			values.push(value);
		} else {
			var pos = text.substr(0, 1);
			var newText = text.slice(1);
			if(children[pos]){
				children[pos].add(newText, value);
			} else {
				children[pos] = new BTree(newText, value);
			}
		}
	};
	
	this.build = function(){
		skipList = new SkipList(values);
		for(var i in children){
			children[i].build();
		}
	};
	
	this.get = function(text){
		if(!text || text == ""){
			return skipList;
		} else if(text=="*"){
			var vals = this.getAllChilds();
			vals = removeDuplicateValues(vals);
			return new SkipList(vals);
		} else {
			var pos = text.substr(0, 1);
			var newText = text.slice(1);
			if(children[pos]){
				return children[pos].get(newText);
			} else {
				return null;
			}
		}
	};
	
	this.getAllChilds = function(){
		var val = values;
		for(var i in children){
			var c = children[i].getAllChilds();
			val = val.concat(c);
		}
		return val;
	};
	
	var removeDuplicateValues = function(arr){
		var uniques = [];
		$.each(arr, function(i, el){
			if($.inArray(el, uniques) === -1) uniques.push(el);
		});
		return uniques;
	};
	
	this.print = function(idt){
		idt = idt || "";
		
		var sp = " ";
		
		var text = "";
		text += "{\n";
		if(values.length > 0) text += idt + sp + "values: " + values + "\n";
		for(var i in children){
			text += idt + sp + i + ": " + children[i].print(idt+sp);
		}
		text += idt + "}\n";
		return text;
	};
	
	this.getValues = function(){
		return values;
	};
	
	if(value != null) this.add(text, value);
};